#include <boost/lexical_cast.hpp>
#include "base/entry.h"
#include "base/entry_manager.h"
#include "base/singleton.h"

namespace test_suite_management
{

class MyEntry : public Entry<>
{
public:
	MyEntry() { }
	MyEntry(DWORD id, const std::string &name) : m_id(id), m_name(name) { }

	virtual ~MyEntry() { }

	KeyType ID() const { return m_id; }
	void SetID(KeyType id) { m_id = id; }

	const std::string & Name() const { return m_name; }
	void SetName(const std::string &name) { m_name = name; }

private:
	KeyType m_id;
	std::string m_name;
};

class MyEntryManager : public Singleton<MyEntryManager>,
	public EntryManager<MyEntry, IndexID, IndexName>
{
};

TEST(test_base, singleton)
{
	std::vector<DWORD> vec;

	for (int i = 0; i < 10000; ++i)
	{
		DWORD id = i;
		std::string name = boost::lexical_cast<std::string>(id);

		MyEntry *entry = new MyEntry(id, name);
		MyEntryManager::Instance().Add(entry);
	}

	for (int i = 0; i < 10000; ++i)
	{
		DWORD id = rand() % 10000;
		MyEntry *entry = MyEntryManager::Instance().GetByID(id);
		EXPECT_TRUE(entry != NULL);

		DWORD tmp = boost::lexical_cast<DWORD>(entry->Name());
		EXPECT_EQ(entry->ID(), tmp);
	}
}

}